{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import experiment_manager as em\n",
    "import far_ho as far\n",
    "from far_ho.examples import hyper_representation as hr, load\n",
    "import tensorflow as tf\n",
    "from time import time"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FAR-HO demo on Meta-learning\n",
    "#### One-shot five-ways experiment on [Omniglot](https://github.com/brendenlake/omniglot) dataset\n",
    "\n",
    "See the paper [Bilevel Programming for Hyperparameter Optimization and Meta-Learning](https://arxiv.org/pdf/1806.04910.pdf)\n",
    "\n",
    "The main code for this experiment is [here](https://github.com/lucfra/FAR-HO/blob/master/far_ho/examples/hyper_representation.py)!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "CLASSES = 5\n",
    "SHOTS = 1\n",
    "META_BATCH_SIZE = 4  # increase this for better performances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "omniglot = load.meta_omniglot(std_num_classes=CLASSES, std_num_examples=(SHOTS*CLASSES, 15*CLASSES), rand=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "name_of_exp = '{}_shot_{}clss_{}MBS_{}'.format(CLASSES, SHOTS, META_BATCH_SIZE, str(time())[-5:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "res = hr.train(omniglot, name_of_exp,\n",
    "               hr.omniglot_model, \n",
    "               T=3, \n",
    "               MBS=META_BATCH_SIZE, \n",
    "               n_episodes_testing=120,\n",
    "               patience=100,\n",
    "               print_every=250)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
